package com.kws.merchant.controller;


import com.kws.common.security.auth.AuthUtil;
import com.kws.merchant.domain.OperationMaintain;
import com.kws.merchant.domain.po.MaintainPo;
import com.kws.merchant.service.OperationMaintainService;
import com.kws.merchant.util.FileUtil;
import com.kws.system.api.domain.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 运维-报修，抢修管理(OperationMaintain)表控制层
 *
 * @author yxy
 * @since 2024-10-28 14:36:38
 */
@RestController
@Api(tags = "运维-报修，抢修管理(OperationMaintain)")
@RequestMapping("operationMaintain")
public class OperationMaintainController {
    /**
     * 服务对象
     */
    @Resource
    private OperationMaintainService operationMaintainService;
 
    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<OperationMaintain>> pageList(@RequestBody MaintainPo maintainPo){
        return R.ok(operationMaintainService.pageList(maintainPo));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "查看")
    public R<OperationMaintain> detailById(@PathVariable Long id) {
        return R.ok(operationMaintainService.detailById(id));
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public R add(@RequestBody OperationMaintain operationMaintain) {
        SysUser sysUser = AuthUtil.getLoginUser().getSysUser();
        operationMaintain.setStatus(2);//待完成
        operationMaintain.setFile(FileUtil.subFileName(operationMaintain.getFile()));
        operationMaintain.setPresenter(sysUser.getUserId());
        operationMaintain.setMerchantId(sysUser.getCompanyId());
        return R.ok(operationMaintainService.save(operationMaintain));
    }

    @PostMapping("/disposeMaintain")
    @ApiOperation(value = "报修-抢修处理")
    public R disposeMaintain(@RequestBody OperationMaintain operationMaintain) {
        return R.ok(operationMaintainService.disposeMaintain(operationMaintain));
    }

    @GetMapping("/fulfilTask/{id}")
    @ApiOperation(value = "完成维修")
    public R fulfilTask(@PathVariable Long id) {
        return R.ok(operationMaintainService.fulfilTask(id));
    }

}
